import os
import sys
import os.path
rootdir = sys.path[0]
templateName = 'Template'

def changeContent(tfile,sstr,rstr):
    try:
        lines=open(tfile,'r').readlines()
        flen=len(lines)
        for i in range(flen):
            if sstr in lines[i]:
                lines[i]=lines[i].replace(sstr,rstr)
        open(tfile,'w').writelines(lines)

    except Exception,e:
        print e

for parent,dirnames,filenames in os.walk(rootdir):
    for dirname in dirnames:
        oriFilename = os.path.join(parent,dirname)
        if templateName in oriFilename:
            destFilename = oriFilename.replace(templateName, sys.argv[1])
            print oriFilename
            print destFilename
            os.rename(oriFilename,destFilename)

for parent,dirnames,filenames in os.walk(rootdir):
    for filename in filenames:
        oriFilename = os.path.join(parent,filename)
        changeContent(oriFilename,templateName,sys.argv[1])
        if templateName in oriFilename:
            destFilename = oriFilename.replace(templateName, sys.argv[1])
            print oriFilename
            print destFilename
            os.rename(oriFilename,destFilename)

#changeContent('1.txt', 'A', 'a')
